package com.cangxuan.app.utils;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;

import java.util.HashMap;
import java.util.Map;

import static android.content.Context.NOTIFICATION_SERVICE;

/**
 * 通知 工具类
 */
public class NotificationUtils {

    public enum NotificationChannelID{
        ordinaryNotificationChannelID
    }

    //创建普通消息通知通道
    static Map<String, NotificationChannel> notificationChannelMap;

    //定义通知管理器
    static NotificationManager notificationManager = null;

    static {
        NotificationChannel ordinaryNotificationChannel =
                new NotificationChannel(NotificationChannelID.ordinaryNotificationChannelID.name(), "普通通知", NotificationManager.IMPORTANCE_DEFAULT);
        //这里就可以继续创建其它的通知通道

        notificationChannelMap = new HashMap<>();
        notificationChannelMap.put(ordinaryNotificationChannel.getId(), ordinaryNotificationChannel);
    }


    public static NotificationManager getNotificationManager(Context context, NotificationChannelID channelId) {
        if (notificationManager == null) {
            notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
        }
        //给通知管理器创建通知通道
        notificationManager.createNotificationChannel(notificationChannelMap.get(channelId.name()));
        return notificationManager;
    }

}
